﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Class_Entity.ObjectTwo;
namespace DataAccess.ObjectTwo
{
   public class D_GetAccount
    {
        ConnectionToDataBase ex = new ConnectionToDataBase();
        DataTable tb = new DataTable();
        Account sx = new Account();
        MD5 gx = new MD5();
        public DataTable GetAccount(String User)
        {

            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.VarChar);
            sqlParameters[0].Value = User;
            return ex.executeSelectQuery("getAccount", sqlParameters);

        }
        public DataTable CheckPin(String User)
        {

            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.VarChar);
            sqlParameters[0].Value = User;
            return ex.executeSelectQuery("CheckPincode", sqlParameters);

        }
        public bool UpdateAccount(Account fx)
        {
            
            SqlParameter[] sqlParameters = new SqlParameter[8];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.USER_NAME;
            sqlParameters[1] = new SqlParameter("@First", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.FIRST_NAME;
            sqlParameters[2] = new SqlParameter("@LastName", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.LAST_NAME;
            sqlParameters[3] = new SqlParameter("@Pic", SqlDbType.VarChar);
            sqlParameters[3].Value = fx.PICTURE;
            sqlParameters[4] = new SqlParameter("@Birth", SqlDbType.VarChar);
            sqlParameters[4].Value = fx.BIRTH_DATE;
            sqlParameters[5] = new SqlParameter("@Phone", SqlDbType.VarChar);
            sqlParameters[5].Value = fx.PHONE_NUMBER;
            sqlParameters[6] = new SqlParameter("@Email", SqlDbType.VarChar);
            sqlParameters[6].Value = fx.EMAIL;
            sqlParameters[7] = new SqlParameter("@Address", SqlDbType.VarChar);
            sqlParameters[7].Value = fx.ADDRESS;
            return ex.executeUpdateQuery("UpdateProfile", sqlParameters);
        }
        public bool InsertAccount(Account fx)
        {
            String NewPass;
            NewPass = gx.getMD5(fx.PASSWORD);
            SqlParameter[] sqlParameters = new SqlParameter[18];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.USER_NAME;
            sqlParameters[1] = new SqlParameter("@First", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.FIRST_NAME;
            sqlParameters[2] = new SqlParameter("@LastName", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.LAST_NAME;
            sqlParameters[3] = new SqlParameter("@Pic", SqlDbType.VarChar);
            sqlParameters[3].Value = fx.PICTURE;
            sqlParameters[4] = new SqlParameter("@Birth", SqlDbType.VarChar);
            sqlParameters[4].Value = fx.BIRTH_DATE;
            sqlParameters[5] = new SqlParameter("@Phone", SqlDbType.VarChar);
            sqlParameters[5].Value = fx.PHONE_NUMBER;
            sqlParameters[6] = new SqlParameter("@Email", SqlDbType.VarChar);
            sqlParameters[6].Value = fx.EMAIL;
            sqlParameters[7] = new SqlParameter("@Address", SqlDbType.VarChar);
            sqlParameters[7].Value = fx.ADDRESS;
            sqlParameters[8] = new SqlParameter("@Bran", SqlDbType.Int);
            sqlParameters[8].Value = fx.BRANCH_ID;
            sqlParameters[9] = new SqlParameter("@Pass", SqlDbType.VarChar);
            sqlParameters[9].Value = NewPass;
            sqlParameters[10] = new SqlParameter("@Role", SqlDbType.Int);
            sqlParameters[10].Value = fx.ROLE;
            sqlParameters[11] = new SqlParameter("@create", SqlDbType.VarChar);
            sqlParameters[11].Value = fx.CREATE_DATE;
            sqlParameters[12] = new SqlParameter("@Des", SqlDbType.VarChar);
            sqlParameters[12].Value = fx.DESCRIPTION;
            sqlParameters[13] = new SqlParameter("@city", SqlDbType.Int);
            sqlParameters[13].Value = fx.CITY_ID;
            sqlParameters[14] = new SqlParameter("@pos", SqlDbType.VarChar);
            sqlParameters[14].Value = fx.POSITION;
            sqlParameters[15] = new SqlParameter("@status", SqlDbType.Int);
            sqlParameters[15].Value = fx.STATUS;
            sqlParameters[16] = new SqlParameter("@active", SqlDbType.Int);
            sqlParameters[16].Value = fx.ACTIVE;
            sqlParameters[17] = new SqlParameter("@Pin", SqlDbType.VarChar);
            sqlParameters[17].Value = fx.PIN_CODE;
            return ex.executeInserQuery("InsertNewAccount", sqlParameters);
        }
        public DataTable SearchAccount(String User)
        {

            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.VarChar);
            sqlParameters[0].Value = User;
            return ex.executeSelectQuery("SearchAccount", sqlParameters);

        }
        public DataTable GetAccountID(int ID)
        {
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.Int);
            sqlParameters[0].Value = ID;
            return ex.executeSelectQuery("SearchAccountID", sqlParameters);
        }
        public bool ChangePass(int val, String pass)
        {
            String tam = gx.getMD5(pass);
            SqlParameter[] sqlParameters = new SqlParameter[2];
            sqlParameters[0] = new SqlParameter("@v_CCode", SqlDbType.Int);
            sqlParameters[0].Value = val;
            sqlParameters[1] = new SqlParameter("@Pass", SqlDbType.VarChar);
            sqlParameters[1].Value = tam;
            return ex.executeUpdateQuery("ChangePasswordEM", sqlParameters);
        }
    }
}
